package com.dy.design_pattern_study.chain_of_responsibility_pattern.dome1;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-22
 * @Content 管理者类
 */
public class Manager {

    protected String name;

    public Manager(String name) {
        this.name = name;
    }

    /**
     * 打印通用模板
     * @param request
     * @return
     */
    private String showBaseMessage(Request request){
        String message =
        "名字：" + name +
                ",内容：" + request.getRequestContent() +
                ",数量：" + request.getNumber();
        return message;
    }

    //较长的方法 -多条分支 -这些都是坏代码的味道
    //类有太多的责任，这违背了单一职责原则，增加新的管理类别，需要修改这个类，违背了开放-封闭原则
    //这里容易变化，把这些公司管理者的类别各做成管理者的子类，这就可以利用多态性来化解分支带来的僵化
    //这里可以用职责链模式来替换
    //得到结果
    public void getResult(String managerLevel, Request request) {

        if (managerLevel.equals("经理")) {
            if (request.getRequestType().equals("请假") && request.getNumber() <= 2) {
                System.out.println(showBaseMessage(request) + ",被批准！");
            } else {
                System.out.println(showBaseMessage(request) + ",无权处理！");
            }
        } else if (managerLevel.equals("总监")) {
            if (request.getRequestType().equals("请假") && request.getNumber() <= 5) {
                System.out.println(showBaseMessage(request) + ",被批准！");
            } else {
                System.out.println(showBaseMessage(request) + ",无权处理！");
            }
        } else if (managerLevel.equals("总经理")) {
            if (request.getRequestType().equals("请假")) {
                System.out.println(showBaseMessage(request) + ",被批准！");
            } else if (request.getRequestType().equals("加薪") && request.getNumber() <= 500) {
                System.out.println(showBaseMessage(request) + ",被批准！");
            } else if (request.getRequestType().equals("加薪") && request.getNumber() > 500){
                System.out.println(showBaseMessage(request) + ",再说吧！");
            }
        }
    }
}
